from fastapi import APIRouter
import os
from fastadmin.utils.Utils import Utils
# 实例化路由器
router = APIRouter()
#获取路由器目录
router_directory = os.path.join(os.path.dirname(os.path.dirname(__file__)), "app")
#实例化工具类
utils = Utils()
#获取目录下所有目录
dir_list = utils.get_dir_dir(router_directory)
#路由器地址
base_router = "fastadmin.app"
for app_dir in dir_list:
    file_name = os.path.join(router_directory, app_dir, "router.py")
    # 判断文件是否存在
    if os.path.exists(file_name):
        # 导入路由
        router_name = app_dir + ".router"
        # print(base_router + "." + router_name)
        # 导入路由文件
        router_module = __import__(base_router + "." + router_name, fromlist=True)
        # 加载路由
        router.include_router(router_module.router)